package Core;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Logger;

/**
 * @author k4rthikR
 *
 */
public class Login {
	Logger log = Logger.getAnonymousLogger();
	DB db = new DB();
	
	public int authenticate(String user, String pass) {
		
		String query = "SELECT count(*) as count from users where user='"+user+"' and pass='"+pass+"'";
		int count=0;
		try {
		Statement st;
		st = db.getCon().createStatement();
		
		log.info("Executing : "+query);
		ResultSet res = st.executeQuery(query);
        
	       while (res.next()) {
	          count = res.getInt("count");
	          if(count!=1) {
	        	  return -1;
	          }
	          else return 1;
	          //log.info("Available port : "+port);
		}	
		}
	    catch (SQLException e) {
			
			log.info(e.getMessage());
		}
	    return -1;
	}
	

}
